package com.speaktoitcookbook.service;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONArray;

import com.google.gson.Gson;
import com.speaktoitcookbook.bean.Material;
import com.speaktoitcookbook.bean.ThirdAccount;
import com.speaktoitcookbook.dao.IMaterialDao;
import com.speaktoitcookbook.dao.factory.DaoFactory;

@WebServlet("/AddThirdAccountService")
public class AddThirdAccountService extends HttpServlet{
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
       doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("application/json");
		
		String thacct = request.getParameter("thacct");
		
		Gson gson = new Gson();
		ThirdAccount account = gson.fromJson(thacct, ThirdAccount.class);
		
		try {
			if (null != account) {
				if (null == DaoFactory.getThirdAccountDao().getThirdAccount(account.getUserID())) {
					DaoFactory.getThirdAccountDao().doCreate(account);
				}
			}
		} catch (Exception e) {
		}
	}
}